1

00:00:00,760  -->  00:00:04,880
In the previous video, we learned about the
Django basic concept. And In this video we

2

00:00:05,120  -->  00:00:14,900
and in this will learn about urls and views deeply. Later,
we will create some page in our project

3

00:00:15,080  -->  00:00:20,380
so we can get better understanding about urls
and views in Django.

4

00:00:20,640  -->  00:00:25,240
But before that, let’s review our code from
previous video first.

5

00:00:26,020  -->  00:00:33,960
This is the ulrs.py file inside our first_project
directory, here we can see that we have admin

6

00:00:33,960  -->  00:00:44,120
urls and root url. The root urls is redirected
to app1.urls, which is urls.py file inside

7

00:00:44,120  -->  00:00:49,080
app1, let’s take a look to that file.

8

00:00:52,480  -->  00:00:59,500
Here we can see that the root urls is redirected
to hello_world function inside views.

9

00:00:59,960  -->  00:01:08,440
Let's take a look at views.py file, here we can
see that hello_world function is returning

10

00:01:08,440  -->  00:01:12,620
simple html expressions “Selamat datang
di Django”

11

00:01:12,700  -->  00:01:24,420
Let’s open our browser and navigate to 127.0.0.1:8000.
Here we get Selamat datang di Django.

12

00:01:24,820  -->  00:01:27,880
Now let’s do some experiments.

13

00:01:28,600  -->  00:01:35,880
Back to visual studio code and manipulate
urls.py file inside first_project directory.

14

00:01:36,540  -->  00:01:44,300
Let’s add app1 here, don’t forget to always
add / in the end of the url.

15

00:01:47,520  -->  00:02:01,020
Let’s back to the browser, refresh, here
we get a 404 error. We can see here that the

16

00:02:01,020  -->  00:02:09,660
available url is admin and app1, Now let’s
try to add app1 in the url.

17

00:02:12,440  -->  00:02:17,500
Here we can see that now we get Selamat datang di Django.

18

00:02:18,440  -->  00:02:26,400
Let’s do another experiment, go back to
vscode, and edit urls.py file inside app1

19

00:02:26,400  -->  00:02:35,500
directory. Let’s add hello_world here. Don’t
forget to always add / in the end of the url.

20

00:02:39,200  -->  00:02:48,600
Let’s back to browser and refresh. Here
we can see that we get 404 error, and we also

21

00:02:48,740  -->  00:02:58,700
see that the available url is admin and app1/hello_world.
That’s why when we try to access only app1

22

00:02:58,700  -->  00:03:08,599
we get a 404 error. Now let’s try to add
hello_world in the url. Okay Cool ! now we

23

00:03:08,600  -->  00:03:10,560
get Selamat datang di Django.

24

00:03:11,020  -->  00:03:19,400
Okay, Let’s do an experiment again, let’s
try to add a new url. Here in the urls.py

25

00:03:19,400  -->  00:03:29,420
file inside app1 directory, let’s add a
new url, let’s say a. This is just for experiment,

26

00:03:29,420  -->  00:03:37,440
you can put whatever you want here. This url
will be redirected to a function inside views

27

00:03:37,720  -->  00:03:46,680
Now we need to create a function in the views,
go to views, and here let’s add a function.

28

00:03:58,060  -->  00:04:01,960
Let’s say we want to display “This is
A”.

29

00:04:10,080  -->  00:04:22,840
Let’s back to browser, navigate to 127.0.0.1:8000/app1/a.
Okay now we get “This is A”

30

00:04:23,500  -->  00:04:26,540
Let’s try to add one more url,

31

00:04:32,900  -->  00:04:35,420
let’s say
we want to add b.

32

00:04:40,640  -->  00:04:45,300
This url will be redirected to b function inside views.

33

00:04:46,160  -->  00:05:03,180
Let’s create b function inside views.py
file. Let’s say we want to display “This is B"

34

00:05:04,060  -->  00:05:17,420
Back to browser again, change a with b, and
here we are. Now we get “This is B”

35

00:05:18,320  -->  00:05:25,480
Okay now let’s try to test all of our url,
let’s change b to hello_world.

36

00:05:26,040  -->  00:05:36,100
Okay we get Selamat datang di Django. Change hello_world
to a. Okay we get “This is A”, and let’s

37

00:05:36,100  -->  00:05:41,580
change again to b. Okay we get “This is
B”.

38

00:05:42,140  -->  00:05:48,580
Okay I think we already done some experiment
and I hope you guys understand about urls

39

00:05:48,580  -->  00:05:54,380
and views concept in Django. If you think that
you are not fully understand the concept,

40

00:05:54,380  -->  00:06:00,360
I recommend you to rewatch this video. Or
if you have further question, you can ask

41

00:06:00,360  -->  00:06:04,660
me and I will do my best to answer all of
your questions.

42

00:06:05,100  -->  00:06:08,260
Thankyou for watching and see you on the next
video!
